package cn.kent.controller;

import cn.kent.config.RabbitConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("hello")
    public void hello() {
        Message msg = MessageBuilder.withBody("hello javaBoy!".getBytes())
                // 设置过期时间, 10s内无人消费将过期
                .setExpiration("10000")
                .build();
        rabbitTemplate.send(RabbitConfig.MESSAGE_DELAY_EXCHANGE_NAME, RabbitConfig.MESSAGE_DELAY_QUEUE_NAME, msg);
    }
}
